home *** CD-ROM | disk | FTP | other *** search
- unit Gridmain;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, Dblup2, DB, DBTables, DBLookup, Mask, DBCtrls,
- ExtCtrls, Grids, DBGrids, Buttons, DBQCombo, Calendar;
-
-
- type
- TForm1 = class(TForm)
- TableGridData: TTable;
- DataSourceGridData: TDataSource;
- TableCust: TTable;
- DataSourceCust: TDataSource;
- DBNavigator1: TDBNavigator;
- DBGrid1: TDBGrid;
- TableGridDataOrderNo: TFloatField;
- TableGridDataCustNo: TFloatField;
- TableGridDataShipVIA: TStringField;
- TableGridDataCheckBox: TBooleanField;
- DBLookupCombo1: TDBLookupCombo;
- DBCheckBox1: TDBCheckBox;
- DBComboBox1: TDBComboBox;
- ImageTrue: TImage;
- ImageFalse: TImage;
- procedure FormCreate(Sender: TObject);
- procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
- Field: TField; State: TGridDrawState);
- procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
- procedure DBCheckBox1Click(Sender: TObject);
- procedure DBGrid1ColExit(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- DBLookupCombo1.Visible := False;
- DBCheckBox1.Visible := False;
- DBComboBox1.Visible := False;
- ImageTrue.Visible := False;
- ImageFalse.Visible := False;
-
- end;
-
- procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
- Field: TField; State: TGridDrawState);
- begin
- { If Field.Index = 4 then
- DBGrid1.Canvas.FillRect(Rect); }
- if (gdFocused in State) then
- begin
- if (Field.FieldName = DBLookupCombo1.DataField) then
- begin
- DBLookupCombo1.Left := Rect.Left + DBGrid1.Left;
- DBLookupCombo1.Top := Rect.Top + DBGrid1.top;
- DBLookupCombo1.Width := Rect.Right - Rect.Left;
- DBLookupCombo1.Height := Rect.Bottom - Rect.Top;
- DBLookupCombo1.Visible := True;
- end
- else if (Field.FieldName = DBCheckBox1.DataField) then
- begin
- DBCheckBox1.Left := Rect.Left + DBGrid1.Left + 1;
- DBCheckBox1.Top := Rect.Top + DBGrid1.top + 1;
- DBCheckBox1.Width := Rect.Right - Rect.Left{ - 1};
- DBCheckBox1.Height := Rect.Bottom - Rect.Top{ - 1};
- DBCheckBox1.Visible := True;
- end
- else if (Field.FieldName = DBComboBox1.DataField) then
- begin
- DBComboBox1.Left := Rect.Left + DBGrid1.Left;
- DBComboBox1.Top := Rect.Top + DBGrid1.top;
- DBComboBox1.Width := Rect.Right - Rect.Left;
- DBComboBox1.Height := Rect.Bottom - Rect.Top;
- DBComboBox1.Visible := True;
- end
- end
- else {in this else area draw any stay behind bit maps}
- begin
- if (Field.FieldName = DBCheckBox1.DataField) then
- begin
- if TableGridDataCheckBox.AsBoolean then
- DBGrid1.Canvas.Draw(Rect.Left,Rect.Top, ImageTrue.Picture.Bitmap)
- else
- DBGrid1.Canvas.Draw(Rect.Left,Rect.Top, ImageFalse.Picture.Bitmap)
- { DBGrid1.Canvas.StretchDraw(Rect, ImageFalse.Picture.Bitmap); }
- end
- { Do bit map dwawing if you want}
- { DBGrid1.Canvas.FillRect(Rect); }
- end;
-
- end;
-
- procedure TForm1.DBGrid1ColExit(Sender: TObject);
- begin
- If DBGrid1.SelectedField.FieldName = DBLookupCombo1.DataField then
- DBLookupCombo1.Visible := false
- else If DBGrid1.SelectedField.FieldName = DBCheckBox1.DataField then
- DBCheckBox1.Visible := false
- else If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then
- DBComboBox1.Visible := false;
- end;
-
- procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
- begin
- if (key <> chr(9)) then
- begin
- if (DBGrid1.SelectedField.FieldName = DBLookupCombo1.DataField) then
- begin
- DBLookupCombo1.SetFocus;
- SendMessage(DBLookupCombo1.Handle, WM_Char, word(Key), 0);
- end
- else if (DBGrid1.SelectedField.FieldName = DBCheckBox1.DataField) then
- begin
- DBCheckBox1.SetFocus;
- SendMessage(DBCheckBox1.Handle, WM_Char, word(Key), 0);
- end
- else if (DBGrid1.SelectedField.FieldName = DBComboBox1.DataField) then
- begin
- DBComboBox1.SetFocus;
- SendMessage(DBComboBox1.Handle, WM_Char, word(Key), 0);
- end;
- end;
- end;
-
- procedure TForm1.DBCheckBox1Click(Sender: TObject);
- begin
- if SendMessage(DBCheckBox1.Handle, BM_GetCheck, 0, 0) = 0 then
- DBCheckBox1.Caption := ' ' + 'False'
- else
- DBCheckBox1.Caption := ' ' + 'True'
- end;
-
-
- end.
-
- Notes > make sure to set the color of the checkbox to match the backgroung
-